package ${package.Controller};

<#if restControllerStyle>
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import org.springframework.web.bind.annotation.*;

import ${package.Entity}.request.${entity}DeleteReq;
import ${package.Entity}.request.${entity}InsertReq;
import ${package.Entity}.request.${entity}PageReq;
import ${package.Entity}.request.${entity}UpdateReq;
import ${package.Entity}.response.${entity}InfoRes;
import ${package.Entity}.response.${entity}PageRes;
import ${package.Service}.${table.serviceName};
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wulis.common.model.request.IdRequest;
import com.wulis.common.wrapper.ApiWrapMapper;
import com.wulis.common.wrapper.ApiWrapper;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * Controller
 *
 * @author ${author}
 * @since ${date}
 */

@Tag(name = "WEB:${table.comment!}")
@RestController
<#if restControllerStyle>
@RequestMapping("web/<#if package.ModuleName?? && package.ModuleName != "">${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@RequiredArgsConstructor
<#else>
@Controller
</#if>
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    private final ${table.serviceName} ${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)};

    @GetMapping("page")
    @Operation(summary = "${table.comment!}:查询(分页)")
    public ApiWrapper<IPage<${entity}PageRes>> page(${entity}PageReq pageReq) {
        return ApiWrapMapper.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.page(pageReq));
    }

    @GetMapping("getInfo")
    @Operation(summary = "${table.comment!}:详情")
    public ApiWrapper<${entity}InfoRes> getInfo(@Valid IdRequest idReq) {
        return ApiWrapMapper.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.getInfo(idReq.getId()));
    }

    @PostMapping("insert")
    @Operation(summary = "${table.comment!}:新增")
    public ApiWrapper<Void> insert(@Valid @RequestBody ${entity}InsertReq insertReq) {
        ${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.insert(insertReq);
        return ApiWrapMapper.success();
    }

    @PutMapping("update")
    @Operation(summary = "${table.comment!}:更新")
    public ApiWrapper<Void> update(@Valid @RequestBody ${entity}UpdateReq updateReq) {
        ${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.update(updateReq);
        return ApiWrapMapper.success();
    }

    @DeleteMapping("delete")
    @Operation(summary = "${table.comment!}:删除")
    public ApiWrapper<Void> delete(@Valid @RequestBody ${entity}DeleteReq deleteReq) {
        ${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.delete(deleteReq);
        return ApiWrapMapper.success();
    }
}
</#if>
